# -*- encoding:utf-8 -*-
# __author__ = 'chenyongbing'
# __poject__ = 'ops_platform'
# __datetime__ = '2022/2/23'
# __name__ = 'java_restart.py'
from .mixin import FlowMixin
from apps.cicd.handles.base import workorder_scale_pod, workorder_pod_status
# Create your code here.

class ScaleFlow(FlowMixin):
    
    def exec__scale(self, action='yes'):
        '''
        确认update，包含执行update调用
        :param action:
        :return:
        '''
        if action == 'no':
            return 'finish', 'error'
        if self.workorder.nodeploy == 1:
            self._logging_warn('在环境 {} 拒绝部署'.format(self.workorder.env.name))
            return 'finish', 'success'
        ret = workorder_scale_pod(self.workorder)
        if not ret:
            return 'fail', 'fail'
        return 'finish', 'success'

    def exec__scale_auto(self, action='yes'):
        '''
        自动执行，并完成结果查询，异步
        :return:
        '''
        if self.workorder.nodeploy == 1:
            self._logging_warn('在环境 {} 拒绝部署'.format(self.workorder.env.name))
            return 'finish', 'success'
        ret = workorder_pod_status(self.workorder)
        if ret:
            return 'finish', 'success'
        else:
            return 'fail', 'fail'
        #### 此处调用异步任务运行更新